//
//  QYLoginTFView.m
//  CarPooling
//
//  Created by Dxc_iOS on 2018/5/18.
//  Copyright © 2018年 代星创. All rights reserved.
//

#import "QYLoginTFView.h"

@implementation QYLoginTFView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self seupUI];
    }
    return self;
}
-(void)seupUI{
//
    _icon = [[UIImageView alloc] init];
    [self addSubview:_icon];
   
//
    _textTF = [[UITextField alloc] init];
    [self addSubview:_textTF];
//
    _separateline = [[UIView alloc] init];
     [self addSubview:_separateline];
    _separateline.backgroundColor = [UIColor grayColor];
//
    
    _secureTextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_secureTextBtn];
    [_secureTextBtn setImage:IMAGE(@"login_secure") forState:UIControlStateNormal];
     [_secureTextBtn addTarget:self action:@selector(secureTextBtnClick:) forControlEvents:UIControlEventTouchUpInside];

    
}
-(void)layoutSubviews{

    [_icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(20);
         make.top.mas_equalTo(self).offset(10);
        make.width.height.mas_equalTo(25);
    }];
    
    
    [_textTF mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.icon.mas_right).offset(10);
        make.top.mas_equalTo(self).offset(10);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(HDScreenWidth-120);
    }];
    
    
    [_separateline mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.icon.mas_right).offset(10);
        make.top.mas_equalTo(self.textTF.mas_bottom).offset(2);
        make.height.mas_equalTo(1.0);
        make.width.mas_equalTo(HDScreenWidth-100);
    }];
    
    [_secureTextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self).offset(-50);
        make.top.mas_equalTo(self).offset(15);
        make.height.mas_equalTo(25);
        make.width.mas_equalTo(25);
    }];
    
}
#pragma mark - Btn ACtion
-(void)secureTextBtnClick:(UIButton *)btn{
    btn.selected = !btn.selected;
    if (btn.isSelected) {
        _textTF.secureTextEntry = YES;
    }else{
        _textTF.secureTextEntry = NO;
    }
    
}

-(void)setSecureTextBtnIsHidden:(BOOL)secureTextBtnIsHidden{
    _secureTextBtnIsHidden = secureTextBtnIsHidden;
    if (_secureTextBtnIsHidden == 1) {
        _secureTextBtn.hidden = YES ;
    }else{
        _secureTextBtn.hidden = NO;
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
